package com.github.chirspan.xaas.rbac.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.chirspan.xaas.mybatis.util.tree.Tree;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author chenpan
 * @ClassName: SysResource
 * description:
 * @date 2018-04-02 14:39
 */
@TableName(value = "xaas_rbac_resource")
@Data
@ApiModel(value = "RbacResource", description = "系统资源", parent = Tree.class)
public class RbacResource extends Tree implements Serializable {

    @TableField(value = "resource_name")
    @ApiModelProperty(value = "资源名称")
    private String resourceName;

    @TableField(value = "resource_url")
    @ApiModelProperty(value = "资源路径")
    private String resourceUrl;

    @TableField(value = "request_method")
    @ApiModelProperty(value = "请求方法 GET/POST/PUT/DELETE/OPTION")
    private String requestMethod;

    @TableField(value = "resource_type")
    @ApiModelProperty(value = "类型(1:应用类菜单 2.按钮)")
    private String resourceType;

    @TableField(value = "permission")
    @ApiModelProperty(value = "权限标识符")
    private String permission;

    @TableField(value = "icon")
    @ApiModelProperty(value = "图标")
    private String icon;

    @TableField(value = "order_no")
    @ApiModelProperty(value = "显示顺序")
    private Integer orderNo;

    @TableField(value = "hidden_menu")
    @ApiModelProperty(value = "菜单是否隐藏")
    private Boolean hiddenMenu;

    @TableField(value = "app_id")
    @ApiModelProperty(value = "所属应用")
    private String appId;

    @TableField(exist = false)
    @ApiModelProperty(value = "多个应用ID集合(查询用)")
    private List<String> appIds;

    @TableField(value = "view_component")
    @ApiModelProperty(value = "前端组件")
    private String viewComponent;

    @TableField(value = "view_url")
    @ApiModelProperty(value = "前端地址")
    private String viewUrl;

    @TableField(value = "is_super")
    @ApiModelProperty(value = "仅超级管理员可用")
    private Boolean isSuper;

    /**
     * 获取id参数字符串
     * @return
     */
    public String getAppIdsStr() {
        if (this.appId != null) {
            return this.appId;
        }
        if (this.appIds != null) {

            return String.join(",", this.appIds.stream().collect(Collectors.toList()));
        }
        return "";
    }
}
